import request from "../util/request";

/**
 * 添加用户信息
 * @returns {Promise<AxiosResponse<any>>}
 */
export const addUser = function () {
    return request.get("/user/add")
}

export const refreshUser = function () {
    return request.get("/user/refresh")
}

/**
 * 编辑用户信息
 * @param userId
 * @returns {Promise<AxiosResponse<any>>}
 */
export const editUser = function (userId) {
    return request.get(`/user/edit/${userId}`)
}

/**
 * 获取用户角色信息
 * @param userId
 */
export const userRole = function (userId) {
    return request.get(`/user-role/get/${userId}`)
}

/**
 * 获取用户列表
 * @param current
 * @param size
 */
export const userList = function (current, size) {
    return request.get(`/user/list/${current}/${size}`)
}

/**
 * 获取用户信息
 * @param userId
 */
export const userInfo = function (userId) {
    return request.get(`/user-role/get/${userId}`)
}

/**
 * 保存用户信息
 * @param roleId
 * @param userInfo
 * @returns {Promise<AxiosResponse<any>>}
 */
// export const userSave = function (roleId, userInfo) {
//     return request.put(`/user/save/role/${roleId}`, userInfo)
// }

/**
 * 保存用户信息
 * @param userInfo
 * @returns {Promise<AxiosResponse<any>>}
 */
export const userSave = function (userInfo) {
    return request.put(`/user/save/role`, userInfo)
}

/**
 * 删除用户信息
 * @param userId
 */
export const userDelete = function (userId) {
    return request.delete(`/user/delete/${userId}`)
}

/**
 * 修改密码
 * @param orgPwd
 * @param newPwd
 */
export const changePassword = function (orgPwd, newPwd) {
    let params = new FormData();
    params.set('orgPwd', orgPwd)
    params.set('newPwd', newPwd)
    return request.post('/user/changePwd', params)
}

/**
 * 重置密码
 * @param userId
 */
export const resetPassword = function (userId) {
    return request.post(`/user/resetPwd/${userId}`)
}

/**
 * 修改用户角色
 */
export const setUserRole = function (userId, roleId) {
    return request.put(`/user-role/set/${userId}/${roleId}`)
}